import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'

import path from "path"


// https://vite.dev/config/
export default defineConfig({
  base: '/dwhd/',
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    })
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "/src"),
      "~@": path.resolve(__dirname, "/src"),
    }
  },
  server: {
    port: 9002  // 添加端口配置
  },
  build: {
    assetsInlineLimit: 4096, // 4kb以下的图片将被转为base64
    rollupOptions: {
      output: {
        chunkFileNames: 'assets/js/[name]-[hash].js',
        entryFileNames: 'assets/js/[name]-[hash].js',
        assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
      },
    },
  },
  experimental: {
    renderBuiltUrl(filename, { hostType, type }) {
      // 为图片添加CDN前缀（如果有需要可以取消注释并修改CDN地址）
      // if (type === 'asset' && /\.(png|jpe?g|gif|svg)$/.test(filename)) {
      //   return `https://your-cdn-domain/${filename}`
      // }
      return filename
    },
  },
})
